<template>
  <div class="tag-card">
    <h2 class="card-title">标签</h2>
    <div class="tag-cloud">
      <span v-for="(item, index) in tags" 
            :key="index" 
            @click="goTagArticleListPage(item.tagId, item.name)"
            class="tag-item">
        {{ item.name }}
      </span>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { getTags } from '@/api/frontend/tag'

const router = useRouter()
const tags = ref([])

// 获取标签
getTags().then((e) => {
  console.log('获取标签数据')
  console.log(e)
  tags.value = e.data
})

const goTagArticleListPage = (id, name) => {
  console.log('跳转 id' + id)
  router.push({path: `/tag/list/${id}/${name}`})
}
</script>

<style scoped>
.tag-card {
  margin-bottom: 0.75rem;
  padding: 1.25rem;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 0;
  box-sizing: border-box;
  min-width: 0;
  width: 100%;
}

.card-title {
  margin-bottom: 0.5rem;
  font-weight: 700;
  color: #111827;
  text-transform: uppercase;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.tag-item {
  display: inline-block;
  background-color: #ecfdf5;
  color: #047857;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.125rem 0.625rem;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tag-item:hover {
  background-color: #047857;
  color: white;
  transform: scale(1.05);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .tag-card {
    background-color: #1f2937;
    border-color: #374151;
  }

  .card-title {
    color: #f9fafb;
  }

  .tag-item:hover {
    background-color: #059669;
    color: white;
  }
}
</style>
